home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / ot papserversample / atalksampleutils.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.3 KB  |  218 lines

  1. /*
  2.     File:        ATalkSampleUtils.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/22/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #ifndef __ATALKSAMPLEUTILS__
  25. #include "ATalkSampleUtils.h"
  26. #endif
  27. #ifndef __OPENTPTAPPLETALK__
  28. #include "OpenTptAppleTalk.h"
  29. #endif
  30. #include <Menus.h>
  31. #include <Devices.h>
  32. #include <Events.h>
  33. #ifndef __STDIO__
  34. #include <stdio.h>
  35. #endif
  36.  
  37. /*******************************************************************************
  38. ** ShowEndpointInfo
  39. **
  40. ********************************************************************************/
  41.  
  42.     static void ShowSize(char* format, SInt32 size)
  43.     {
  44.         if ( size == T_INFINITE )
  45.             fprintf(stderr, "%sT_INFINITE\n", format);
  46.         else if ( size == T_INVALID )
  47.             fprintf(stderr, "%sT_INVALID\n", format);
  48.         else
  49.             fprintf(stderr, "%s%ld\n", format, size);
  50.     }
  51.     
  52. void ShowEndpointInfo(EndpointRef ep)
  53. {
  54.     TEndpointInfo     info;
  55.     OSStatus        err;
  56.     SInt32             flags;
  57.     char*            type;
  58.     Boolean         ndComma;
  59.     
  60.     err = OTGetEndpointInfo(ep, &info);
  61.     fprintf(stderr, " TEndpointInfo:\n");
  62.     if ( err != kOTNoError )
  63.     {
  64.         fprintf(stderr, "     ERROR! = %d\n", err);
  65.     }
  66.     else
  67.     {
  68.         ShowSize("       addr = ", info.addr);
  69.         ShowSize("    options = ", info.options);
  70.         ShowSize("       tsdu = ", info.tsdu);
  71.         ShowSize("      etsdu = ", info.etsdu);
  72.         ShowSize("    connect = ", info.connect);
  73.         ShowSize("     discon = ", info.discon);
  74.         
  75.         fprintf(stderr, "   servtype = ");
  76.         switch ( info.servtype )
  77.         {
  78.             case T_COTS:        type = "T_COTS"; break;
  79.             case T_COTS_ORD:    type = "T_COTS_ORD"; break;
  80.             case T_CLTS:        type = "T_CLTS"; break;
  81.             case T_TRANS:        type = "T_TRANS"; break;
  82.             case T_TRANS_ORD:    type = "T_TRANS_ORD"; break;
  83.             case T_TRANS_CLTS:    type = "T_TRANS_CLTS"; break;
  84.             default:            type = NULL;
  85.         }
  86.         if ( type != NULL )
  87.             fprintf(stderr, "%s\n", type);
  88.         else
  89.             fprintf(stderr, "%lu\n", info.servtype);
  90.             
  91.         flags = info.flags;
  92.         fprintf(stderr, "      flags = ", info.flags);
  93.         ndComma = false;
  94.         if ( flags & T_SENDZERO )
  95.         {
  96.             flags &= ~T_SENDZERO;
  97.             fprintf(stderr, "T_SENDZERO");
  98.             ndComma = true;
  99.         }
  100.         if ( flags & T_XPG4_1 )
  101.         {
  102.             flags &= ~T_XPG4_1;
  103.             if ( ndComma )
  104.                 fprintf(stderr, ", ");
  105.             ndComma = true;
  106.             fprintf(stderr, "T_XPG4_1");
  107.         }
  108.         if ( flags & T_CAN_RESOLVE_ADDR )
  109.         {
  110.             flags &= ~T_CAN_RESOLVE_ADDR;
  111.             if ( ndComma )
  112.                 fprintf(stderr, ", ");
  113.             ndComma = true;
  114.             fprintf(stderr, "T_CAN_RESOLVE_ADDR");
  115.         }
  116.         if ( flags & T_CAN_SUPPLY_MIB )
  117.         {
  118.             flags &= ~T_CAN_SUPPLY_MIB;
  119.             if ( ndComma )
  120.                 fprintf(stderr, ", ");
  121.             ndComma = true;
  122.             fprintf(stderr, "T_CAN_SUPPLY_MIB");
  123.         }
  124.         if ( flags != 0 )
  125.         {
  126.             if ( ndComma )
  127.                 fprintf(stderr, ", ");
  128.             fprintf(stderr, "%08lX", flags);
  129.             
  130.         }
  131.         fprintf(stderr, "\n");
  132.     }
  133. }
  134.  
  135. /*******************************************************************************
  136. ** ShowEndpointState
  137. ********************************************************************************/
  138.  
  139. void ShowEndpointState(EndpointRef ep, char* prefixString)
  140. {
  141.     char*     strPtr;
  142.     OTResult     state;
  143.     
  144.     state = OTGetEndpointState(ep);
  145.     
  146.     fprintf(stderr, "%sState = %d, ", prefixString, state);
  147.     switch ( state )
  148.     {
  149.         case T_UNINIT:
  150.             strPtr = "T_UNINIT";
  151.             break;
  152.         case T_UNBND:
  153.             strPtr = "T_UNBND";
  154.             break;
  155.         case T_IDLE:
  156.             strPtr = "T_IDLE";
  157.             break;
  158.         case T_OUTCON:
  159.             strPtr = "T_OUTCON";
  160.             break;
  161.         case T_INCON:
  162.             strPtr = "T_INCON";
  163.             break;
  164.         case T_DATAXFER:
  165.             strPtr = "T_DATAXFER";
  166.             break;
  167.         case T_OUTREL:
  168.             strPtr = "T_OUTREL";
  169.             break;
  170.         case T_INREL:
  171.             strPtr = "T_INREL";
  172.             break;
  173. //        case T_INFLUX:
  174. //            strPtr = "T_INFLUX";
  175. //            break;
  176.         default:
  177.             strPtr = "Unknown";
  178.     }
  179.     fprintf(stderr,"%s\n", strPtr);
  180. }
  181.  
  182. /*******************************************************************************
  183. ** ShowFullEndpointData
  184. **
  185. ********************************************************************************/
  186.  
  187. void ShowFullEndpointData(EndpointRef ep)
  188. {
  189.     fprintf(stderr, "FULL ENDPOINT INFO FOR ENDPOINT AT %08lX\n", ep);
  190.     
  191.     fprintf(stderr, "               Mode = %s\n", (OTIsSynchronous(ep) ? "Synchronous" : "Asynchronous"));
  192.  
  193.     ShowEndpointState(ep, "              ");
  194.     
  195.     fprintf(stderr, "             Look() = %d\n", OTLook(ep));
  196.     
  197.     ShowEndpointInfo(ep);
  198.     
  199.     fprintf(stderr, "");
  200. }
  201.  
  202. /*******************************************************************************
  203. ** ShowDDPAddress -- print out an AppleTalk DDP address
  204. ********************************************************************************/
  205.  
  206. void ShowDDPAddress(DDPAddress* addr)
  207. {
  208.     if (addr->fAddressType == AF_ATALK_DDP ||
  209.         addr->fAddressType == AF_ATALK_DDPNBP)
  210.     {
  211.         fprintf(stderr, "Net $%04X, Node $%02X, Socket $%02X, Type $%02X",
  212.             addr->fNetwork, addr->fNodeID, addr->fSocket, addr->fDDPType);
  213.     }
  214.     else
  215.         fprintf(stderr, "Not DDP Addr!");
  216. }
  217.  
  218.